﻿<%@ Control Language="C#" ClassName="PaymentsInput" Inherits="Dimok.Web.UI.TableControl" %>
<script runat="server">
	protected override void OnInit(EventArgs e) {
		base.OnInit(e);
		Page.LoadComplete += new EventHandler(Page_LoadComplete);
		GridViewEx.RowInserting += GridViewEx_RowInserting;
	}

	void GridViewEx_RowInserting(object sender, GridViewInsertEventArgs e) {
		e.InsertingValues["LoanID"] = LoanID;
	}

	void Page_LoadComplete(object sender, EventArgs e) {
		if(IsPostBack)
			GridViewEx.DataBind();
	}

	public int LoanID { get {
		var i = 0;
		int.TryParse(Lib.GetProperty(Parent, "LoanID")+"", out i);
		return i;
	} }
	public int PaymentID { get { return (int)Lib.GetProperty(Parent, "PaymentID"); } }
</script>
<asp:UpdatePanel ID="upPaymentsInput" UpdateMode="Always" runat="server">
	<ContentTemplate>
<DS:FunctionDataSource ID="dsPaymentsInput" SelectList="PaymentID,Amount,DatePaid,Status,StatusID,InterestPart,ID,InputDate,InputUser,WaterFall,WaterFallID" 
		SelectViewName="v_PaymentInput WHERE ISNULL(@Param1,0) IN (0,PaymentID) AND LoanID = @Param2" OrderBys="DatePaid,ID"
		UpdateViewName="t_PaymentInput" InsertViewName="t_PaymentInput" runat="server">
	<SelectParameters><asp:ControlParameter PropertyName="Page.PaymentID" Name="Param1" Type="Int32" /></SelectParameters>
	<SelectParameters><asp:ControlParameter PropertyName="Page.LoanID" Name="Param2" Type="Int32" /></SelectParameters>
</DS:FunctionDataSource>
<UI:GridViewEx DataSourceID="dsPaymentsInput" DataKeyNames="ID" AllowEdit="true" RowStyle-BackColor="#f3f2f7" 
								ShowDelete="true" AllowSorting="true" ShowFooter="true" ShowSearch="true" AutoGenerateColumns="false" runat="server">
	<Columns>
		<asp:TemplateField HeaderText="Pmt$" SortExpression="Amount" ItemStyle-HorizontalAlign="Right" ItemStyle-Font-Bold="true">
			<ItemTemplate>
				<%#Eval("Amount")%>
				<asp:ImageButton Height="16" Width="16" ImageUrl="~/images/History.gif" runat="server" OnClientClick=<%#Eval("ID","paymentHistory(this,{0},\"Amount\",\"t_PaymentInput\");return false")%> CssClass="TipMe" style="cursor:hand" ToolTip="Click to see hostory"/>
			</ItemTemplate>
			<EditItemTemplate>				<asp:TextBox ID="txtAmount" Text='<%#Bind("Amount")%>' runat="server"/></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="Amount" runat="server" /></FooterTemplate>
		</asp:TemplateField>
		<asp:TemplateField HeaderText="DatePaid" SortExpression="DatePaid">
			<ItemStyle Font-Bold="true" />
			<ItemTemplate>
				<%#Eval("DatePaid","{0:MM/dd/yyyy}")%>
				<asp:ImageButton Height="16" Width="16" ImageUrl="~/images/History.gif" runat="server" OnClientClick=<%#Eval("ID","paymentHistory(this,{0},\"DatePaid\",\"t_PaymentInput\");return false")%> CssClass="TipMe" style="cursor:hand" ToolTip="Click to see hostory"/>
			</ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtDatePaid" Text='<%#Bind("Datepaid","{0:MM/dd/yyyy}")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="DatePaid" runat="server" /></FooterTemplate>
		</asp:TemplateField>
		<asp:TemplateField HeaderText="Status" SortExpression="Status" ItemStyle-Font-Bold="true">
			<ItemTemplate><%#Eval("Status")%></ItemTemplate>
			<FooterTemplate>
			<DS:StatesDataSource  Access="Add" TableName="t_Payment" OrderBys="StateFlowPos" ID="dsStates" runat="server" />
			<asp:DropDownList DataSourceID="dsStates" DataTextField="Name" DataValueField="ID" ID="StatusID" runat="server" />
			</FooterTemplate>
			</asp:TemplateField>
		<asp:TemplateField HeaderText="WaterFall" SortExpression="WaterFall" ItemStyle-Font-Bold="true">
			<ItemTemplate><%#Eval("WaterFall")%></ItemTemplate>
			<FooterTemplate>
			<DS:TableDataSource SelectViewName="ts_PaymentWaterFall" OrderBys="Pos" ID="dsWaterFalls" runat="server" />
			<asp:DropDownList DataSourceID="dsWaterFalls" DataTextField="Name" DataValueField="ID" ID="WaterFallID" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>
		<asp:TemplateField HeaderText="Int Part" SortExpression="InterestPart" ItemStyle-HorizontalAlign="Right" ItemStyle-Font-Bold="true">
			<ItemStyle Font-Bold="true" />
			<ItemTemplate><%#Eval("InterestPart")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtInterestPart" Text='<%#Bind("InterestPart")%>' runat="server"/></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="InterestPart" runat="server" /></FooterTemplate>
		</asp:TemplateField>
		<asp:BoundField DataField="InputUser" HeaderText="InputUser" SortExpression="InputUser" />
		<asp:BoundField DataField="InputDate" HeaderText="InputDate" SortExpression="InputDate" />
		<asp:BoundField DataField="PaymentID" HeaderText="PaymentID" SortExpression="PaymentID" />
		<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
	</Columns>
</UI:GridViewEx>
</ContentTemplate>
</asp:UpdatePanel>
